import type { ResultItem, StringKey_NumberData_Object } from "./Utils";

class Processer {
    private letterLeft: StringKey_NumberData_Object = {};
    private word: string = "";

    init(word: string) {
        const letters = "qwertyuiopasdfghjklzxcvbnm";
        for (let i = 0; i < letters.length; i++) {
            this.letterLeft[letters[i]] = 0;
        }
        this.word = word;
    }

    parseLetters(word: string) {
        for (let i = 0; i < word.length; i++) {
            this.letterLeft[word[i]] += 1;
        }
    }

    guess(word: string) {
        const result: ResultItem[] = [];
        for (let i = 0; i < word.length; i++) {
            if (this.letterLeft[word[i]] > 0) {
                if (this.word[i] == word[i]) {
                    result.push({
                        letter: word[i],
                        status: "correct",
                    });
                } else {
                    result.push({
                        letter: word[i],
                        status: "include",
                    });
                }
                this.letterLeft[word[i]] -= 1;
            } else {
                result.push({
                    letter: word[i],
                    status: "exclude",
                });
            }
        }
        // return: Emit out data
    }
}

export default new Processer();
